package com.lekang.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.system.domain.Floor;
import com.lekang.system.service.IFloorService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 楼层Controller
 * 
 * @author zhihao
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/system/floor")
public class FloorController extends BaseController
{
    @Autowired
    private IFloorService floorService;

    /**
     * 查询楼层列表
     */
    @PreAuthorize("@ss.hasPermi('system:floor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Floor floor)
    {
        startPage();
        List<Floor> list = floorService.selectFloorList(floor);
        return getDataTable(list);
    }

    /**
     * 导出楼层列表
     */
    @PreAuthorize("@ss.hasPermi('system:floor:export')")
    @Log(title = "楼层", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Floor floor)
    {
        List<Floor> list = floorService.selectFloorList(floor);
        ExcelUtil<Floor> util = new ExcelUtil<Floor>(Floor.class);
        util.exportExcel(response, list, "楼层数据");
    }

    /**
     * 获取楼层详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:floor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(floorService.selectFloorById(id));
    }

    /**
     * 新增楼层
     */
    @PreAuthorize("@ss.hasPermi('system:floor:add')")
    @Log(title = "楼层", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Floor floor)
    {
        return toAjax(floorService.insertFloor(floor));
    }

    /**
     * 修改楼层
     */
    @PreAuthorize("@ss.hasPermi('system:floor:edit')")
    @Log(title = "楼层", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Floor floor)
    {
        return toAjax(floorService.updateFloor(floor));
    }

    /**
     * 删除楼层
     */
    @PreAuthorize("@ss.hasPermi('system:floor:remove')")
    @Log(title = "楼层", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(floorService.deleteFloorByIds(ids));
    }





    /**
     * 接口1：查询所有楼层的全链路关联数据
     */
    @GetMapping("/all-relations")
    public AjaxResult selectAllFloorRelations() {
        List<Floor> floorList = floorService.selectFloorWithAllRelations();
        return AjaxResult.success("查询成功", floorList);
    }

    /**
     * 接口2：根据楼层ID查询单条全链路数据
     * @param id 楼层ID
     */
    @GetMapping("/all-relations/{id}")
    public AjaxResult selectFloorRelationsById(@PathVariable("id") Long id) {
        Floor floor = floorService.selectFloorWithAllRelationsById(id);
        return floor != null ? AjaxResult.success("查询成功", floor) : AjaxResult.error("未找到该楼层");
    }

}
